﻿CREATE FUNCTION [dbo].[fs_Payment_Base](
	@StateID int
)RETURNS TABLE
AS

RETURN 
SELECT L_B.LoanID, L_B.FirstName, L_B.LastName,P.Amount,P.DatePaid, P.StatusDate, P.StatusUser, L_B.Status AS LoanStatus
FROM v_List_Base AS L_B INNER JOIN
                      v_Payment AS P ON P.LoanID = L_B.LoanID INNER JOIN
                      dbo.fs_Payment_Read(DEFAULT, @StateID) AS fs_Loans ON L_B.LoanID = fs_Loans.LoanID
                      WHERE P.StatusID = @StateID
